package com.excell.support.excellbasic;

import lombok.Setter;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.util.ArrayList;

/**
 * @User c.c
 * @Since 2022/12/9
 * @Time 10:10
 * @Description 工作簿
 * TODO 目前仅支持单工作簿
 */
@Setter
public class ExcellSheetBasic<T> {

  //TODO 多张sheet表格
  private ArrayList<ExcellSheetBasic<T>> workbooklist = new ArrayList<>();
  private HSSFWorkbook workbook;
  private ExcellCellBasics<T> excellCellBasics;

  private ExcellSheetBasic(ArrayList<ExcellSheetBasic<T>> workbooklist, HSSFWorkbook workbook) {
    this.workbooklist = workbooklist;
    this.workbook = workbook;
  }

  private ExcellSheetBasic() {
  }

  public static <T> ExcellSheetBasic<T> getInstance() {
    return new ExcellSheetBasic<>(null, new HSSFWorkbook());
  }

  public static <T> ExcellSheetBasic<T> getInstance(String tableName) {
    HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
    hssfWorkbook.createSheet(tableName);
    return new ExcellSheetBasic<>(null,hssfWorkbook);
  }

  public HSSFWorkbook getWorkbook() {
    return workbook;
  }

  public ExcellCellBasics<T> getExcellCellBasics() {
    return excellCellBasics;
  }

  public void initWorkBook(HSSFWorkbook wb, ExcellCellBasics<T> excellCellBasics) {
    this.workbook = wb;
    this.excellCellBasics = excellCellBasics;
  }

  @Deprecated
  public static<T> ExcellSheetBasic<T> updateWorkBook(String sheetName, ExcellCellBasics<T> newExcellCellBasics){
    ExcellSheetBasic<T> newExcellSheetBasic = ExcellSheetBasic.getInstance(sheetName);
    newExcellSheetBasic.initWorkBook(newExcellSheetBasic.getWorkbook(),newExcellCellBasics);
    return newExcellSheetBasic;
  }
}
